package bitmap;

import colour.Colour;

/**
 * This is class which is used for dealing with all the operation on the Bitmap
 * stored in PPM and contain all data needed by a bitmap. PPM is divided by two
 * types (P3,P6).
 * 
 * @author Yuting Wu
 * @author Kan Lin
 * @author Bing Dong
 * @version 0.1
 * @param magicNumber
 *            the number shows the type of format, P3 is ASCII and P6 is binary
 * 
 * @param width
 *            the width of the image
 * @param height
 *            the height of the image
 * 
 * @param maxColourValue
 *            maximal value of colour component can be handled
 * 
 * @param RGB
 *            vector for the RGB value, nheight*height+width is used to locate
 *            the element
 * 
 * @param colour
 *            a single data type of colour component
 * 
 */
public class Bitmap {
	private String magicNumber = "0"; // the number shows the type of format

	// P3 is ASCII and P6 is binary
	private int width = 1; // the width of the image
	private int height = 1; // the height of the image

	// maximal value of colour component can be handled
	private int maxColourValue = 255;
	private Colour[][] pixels; // array for the rgb value,

	public Bitmap() {
		super();
	}

	public Bitmap(String magicNum, final int newWidth, final int newHeight,
			final int maxColValue, Colour[][] rgbInASCII) {
		this.magicNumber = magicNum;
		this.width = newWidth;
		this.height = newHeight;
		this.maxColourValue = maxColValue;
		this.pixels = rgbInASCII;
	}

	/**
	 * This is a method for getting the width from the class
	 * 
	 * @return width
	 */
	public int getWidth() {
		return this.width;
	}

	/**
	 * This is a method for getting the width from the class
	 * 
	 * @return height
	 */
	public int getHeight() {
		return this.height;
	}

	/**
	 * @return the magicNumber
	 */
	public String getMagicNumber() {
		return magicNumber;
	}

	/**
	 * @return the maxColourValue
	 */
	public int getMaxColourValue() {
		return maxColourValue;
	}
	
	public boolean checkNumEuqal(){
		return (pixels.length == height)&&(pixels[0].length == width);
	}
	
	/**
	 * This is a method for get Colour by index.
	 * 
	 * @param hPos
	 *            position in the height
	 * @param wPos
	 *            position in the width
	 * 
	 * @return a array with the pixel on the given position
	 * 
	 */
	public Colour getColourIndex(int hPos, int wPos) {
		return pixels[hPos][wPos];
	}
	
	/**
	 * This is a method for modify Colour of pixels.
	 * 
	 * @param iWidth
	 *            position of the pixels in the width
	 * @param iHeight
	 *            position of the pixels in the height
	 * @param newRed
	 *            a value for the new red of pixels
	 * @param newGreen
	 *            a value for the new green of pixels
	 * @param newBlue
	 *            a value for the new blue of pixels
	 * 
	 * @param maxColourValue
	 *            the maximal value of the colour component
	 * 
	 * @return a type of boolean shows whether the operation is sucessful
	 */
	public boolean modifyColour(int iWidth, int iHeight, int newRed,
			int newGreen, int newBlue, int maxColourValue) {
		Colour col = new Colour(newRed, newGreen, newBlue);
		pixels[iHeight][iWidth] = col;
		return true;
	}

}
